Passed
Pull Request — master (#77)
by
unknown
03:14
created

SmileyConf.getRegex   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
export default class SmileyConf {
2
    static getSmileys() {
3
        return JSINFO.SMILEY_CONF;
0 ignored issues
show
Bug introduced by
The variable JSINFO seems to be never declared. If this is a global, consider adding a /** global: JSINFO */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
4
    }
5
6
    /**
7
     * Regex escape as recommended by MDN
8
     *
9
     * @param {string} string
10
     * @returns {string}
11
     */
12
    static escapeRegExp(string) {
13
        return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
14
    }
15
16
    /**
17
     * Regex from conf
18
     *
19
     * @returns {RegExp}
20
     */
21
    static getRegex() {
22
        const smileyGroups = this.getSmileys().map(smiley => `(${SmileyConf.escapeRegExp(smiley.syntax)})`);
23
        const regexstring = smileyGroups.join('|');
24
        return new RegExp(`${regexstring}`);
25
    }
26
}
27